// File_BPA.cpp: implementation of the CFile_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Bse/File_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFile_BPA::CFile_BPA()
{
	memset(m_strFileName,'\0',MAX_FILENAME);
}

CFile_BPA::~CFile_BPA()
{

}

void CFile_BPA::SetFileName(char *FileName)
{
	strcpy(m_strFileName,FileName);
}

bool CFile_BPA::Load()
{
//	bool bInDataField = false;
//	bool bInChangeField = false;

	FILE* pFile = fopen(m_strFileName,"r");
	if (!pFile)
	{
		printf("Error in (CFile_BPA: Load): file %s cannot be read!\n",m_strFileName);
		return false;
	}

	if (!LoadEx(pFile))
	{
		printf("Error in (CFile_BPA: Load): LoadEx(pFile)\n");
		return false;
	}

	if (fclose(pFile))
	{
		printf("Error in (CFile_BPA: Load): fail to close file %s!\n",m_strFileName);
		return false;
	}

	DetachAllCards();

	return true;
}

bool CFile_BPA::Save()
{
	return SaveAs(m_strFileName);
}

bool CFile_BPA::SaveAs(char *strFileName)
{
/*	if (!UpdateAllCards())
		return false;*/

	FILE* pFile = fopen(strFileName,"w");
	if (!pFile)
	{
		printf("Error in (CFile_BPA: SaveAs): save to file %s did not succeed!\n",strFileName);
		return false;
	}

	if (!SaveEx(pFile))
	{
		printf("Error in (CFile_BPA: SaveAs): SaveEx(pFile)\n");
		return false;
	}
	
	if (fclose(pFile))
	{
		printf("Error in (CFile_BPA: SaveAs): fail to close file %s!\n",strFileName);
		return false;
	}
	
	return true;
}